# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: modles.py
里面包括所有用到的类，类里面处理数据，存储，删除，修改等
返回给中间的接口对象让接口对象去返回给视图层显示
Author: kij
Create Date: 2021/2/22
-------------------------------------------------
"""
from db import db_handler


class Base:
	"""
	里面包括通用的数据存储方法和查询方法
	"""

	def save_data(self):
		db_handler.save_data(self)

	@classmethod
	def get_data(cls, user_name):
		obj = db_handler.get_data(cls, user_name)
		return obj


class Admin(Base):
	def __init__(self, user_name, user_password):
		self.user_name = user_name
		self.user_password = user_password


class Teacher(Base):

	def __init__(self, user_name, user_password, admin_name):
		self.user_name = user_name
		self.user_password = user_password
		self.admin_name = admin_name
		# 教授的课程
		self.lessons = []

	# 查看课程
	def show_lesson(self):
		return self.lessons

	# 新增课程
	def add_lesson(self, lesson):
		self.lessons.append(lesson)
		self.save_data()

	# 拿到课程对应的学生
	def get_student(self, lesson_name):
		lesson = Lesson.get_data(lesson_name)
		return lesson.student_list

	# 修改学生分数
	def change_score(self, student_name, lesson_name, num):
		student = Student.get_data(student_name)
		student.score_dict[lesson_name] = num
		student.save_data()


class Student(Base):

	def __init__(self, user_name, user_password):
		self.user_name = user_name
		self.user_password = user_password
		self.school = None
		self.lessons = []
		self.score_dict = {}

	# 新增学校
	def add_school(self, school_name):
		self.school = school_name
		self.save_data()

	def add_lesson(self, lesson):
		self.lessons.append(lesson)
		# 分数默认为0
		self.score_dict[lesson] = 0
		self.save_data()
		lesson = Lesson.get_data(lesson)
		lesson.student_list.append(
			self.user_name
		)
		lesson.save_data()


class School(Base):

	def __init__(self, school_name, school_address, admin_name):
		self.user_name = school_name  # user_name 为了方便拿到数据统一用user_name
		self.school_address = school_address
		self.admin_name = admin_name


class Lesson(Base):
	'''课程信息'''

	def __init__(self, lesson_name, lesson_time, lesson_price, school_name):
		self.user_name = lesson_name
		self.lesson_time = lesson_time
		self.lesson_price = lesson_price
		self.school_name = school_name
		self.student_list = []
